/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network.packets;

import utils.Utils;

/**
 *
 * @author Kvest
 */
public class DistrictStatisticResponce extends Packet
{
    private Item[] result;
    
    public DistrictStatisticResponce(byte[] data)
    {
        super(DISTRICTS_STATISTIC_RESPONCE, data);
    }
    
    protected void parse(byte[] data) 
    {
        int offset = 2;
        
        //Размер массива
        byte[] tmp = new byte[4];
        System.arraycopy(data, offset, tmp, 0, tmp.length);
        offset += tmp.length;
        int size = Utils.byteToInt(tmp);
        
        result = new Item[size];
        for (int i = 0; i < size; ++i)
        {
            //ИД стоянки
            System.arraycopy(data, offset, tmp, 0, tmp.length);
            offset += tmp.length;
            result[i] = new Item(Utils.byteToInt(tmp));
            
            //кол-во водителей на стоянке
            System.arraycopy(data, offset, tmp, 0, tmp.length);
            offset += tmp.length;
            result[i].driversCount = Utils.byteToInt(tmp);
                    
            //кол-во заказов на стоянке
            System.arraycopy(data, offset, tmp, 0, tmp.length);
            offset += tmp.length; 
            result[i].ordersCount = Utils.byteToInt(tmp);
        }
    }
    
    public void print() 
    {
        String value = "DistrictStatisticResponce:\n";
        for (int i = 0; i < result.length; ++i)
        {
            value += "\t" + result[i].id + "-" + result[i].driversCount + "-" + result[i].ordersCount + "\n";
        }
        
        System.out.println(value + "-------------------");
    }

    public int size()
    {
        return result.length;
    }

    public Item getItem(int index)
    {
        return result[index];
    }

    public class Item
    {
        public int id;
        public int driversCount;
        public int ordersCount;
        
        public Item(int id)
        {
            this.id = id;
        }
    }
}
